#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

bool isPerfectSquare(int num) {
    int root = sqrt(num);
    return root * root == num;
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

  
    vector<int> pre(n + 1, 0);
    for (int i = 1; i <= n; ++i) {
        pre[i] = pre[i - 1] + A[i - 1];
    }

 
    while (q--) {
        int x;
        cin >> x;
        int count = 0;
        for (int i = x; i <= n; ++i) {
            int sum = pre[i] - pre[x - 1];
            if (isPerfectSquare(sum)) {
                count++;
            }
        }
        cout << count << endl;
    }

    return 0;
}
